package com.quick.im.client.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quick.im.client.interfaces.IMessageRecordOfflineService;
import com.quick.im.client.mapper.MessageRecordOfflineMapper;
import com.quick.im.common.entity.domian.MessageRecordOffline;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
* (MessageRecordOffline) 服务实现类
* @author xhh
* @since 2024-12-19
*/
@Service
@Slf4j
public class MessageRecordOfflineServiceImpl extends ServiceImpl<MessageRecordOfflineMapper, MessageRecordOffline> implements IMessageRecordOfflineService {

    @Setter(onMethod_ = @Autowired)
    private MessageRecordOfflineMapper dataMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public MessageRecordOffline saveMessageRecordOffline (MessageRecordOffline request) {
        save(request);
        return request;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void  deleteMessageRecordOfflineById (Integer id) {
        removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public MessageRecordOffline updateMessageRecordOffline (MessageRecordOffline request) throws IllegalAccessException, NoSuchMethodException {

        updateById(request);
        return request;
    }

    @Override
    public Page<MessageRecordOffline> listMessageRecordOffline (MessageRecordOffline request) throws IllegalAccessException, NoSuchMethodException {
        LambdaQueryWrapper<MessageRecordOffline> query = Wrappers.lambdaQuery();
        Page<MessageRecordOffline> page = new Page<>(request.getPage(),request.getPageSize());
        Page<MessageRecordOffline> res = page(page, query);
        return res;
    }

    @Override
    public  MessageRecordOffline getMessageRecordOfflineById (Integer id){
        Optional<MessageRecordOffline> data = Optional.ofNullable(getById(id));
        return data.orElse(null);
    }

}

